import 'package:flutter/material.dart';

/// page以dialog形式展示
class DialogPage<T> extends Page<T> {
  const DialogPage({
    required LocalKey key,
    required String name,
    required this.pageBuilder,
    this.transitionsBuilder,
  }) : super(key: key, name: name);

  final RoutePageBuilder pageBuilder;

  final RouteTransitionsBuilder? transitionsBuilder;

  @override
  Route<T> createRoute(BuildContext context) {
    return PageRouteBuilder(
      settings: this,
      transitionsBuilder: transitionsBuilder ??
          (BuildContext context, Animation<double> animation,
              Animation<double> secondaryAnimation, Widget child) {
            return FadeTransition(
              opacity: Tween<double>(begin: 0, end: 1).animate(animation),
              child: Semantics(
                scopesRoute: true,
                explicitChildNodes: true,
                child: child,
              ),
            );
          },
      opaque: false,
      pageBuilder: this.pageBuilder,
    );
  }
}
